import Flutter
import UIKit

public class AvAudioSessionPlugin: NSObject, FlutterPlugin {
  public static func register(with registrar: FlutterPluginRegistrar) {
    let channel = FlutterMethodChannel(name: "av_audio_session", binaryMessenger: registrar.messenger())
    let instance = AvAudioSessionPlugin()
    registrar.addMethodCallDelegate(instance, channel: channel)
  }

  public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
    switch call.method {
    case "getPlatformVersion":
      result("iOS " + UIDevice.current.systemVersion)
    case "setAppleAudioConfiguration":
        if let args = call.arguments as? Dictionary<String, Any> {
            if let configuration = args["configuration"] as? Dictionary<String, Any> {
                AudioUtils.setAppleAudioConfiguration(configuration)
                result(true)
                return
            }
        }
        result(false)
    default:
      result(FlutterMethodNotImplemented)
    }
  }
}
